#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.basic.security.filter;

import ${package}.basic.security.oauth2.config.YkSecurityProperties;
import ${package}.common.component.service.RedisService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;

import javax.annotation.Resource;

/**
 * Description: 过滤器注册
 *
 * @author wenxiaopeng
 * @date 2021/04/10 17:56
 *
 * <pre>
 *              ${copyright}
 *      Copyright (c) 2019. All Rights Reserved.
 * </pre>
 */
@Configuration
public class FilterConfiguration {

	@Resource
	private YkSecurityProperties ykSecurityProperties;
	@Resource
	private AuthenticationFailureHandler authenticationFailureHandler;
	@Resource
	private RedisService redisService;


	@Bean
	@Order(1)
	@ConditionalOnProperty("yk.security.pwdEncrypt")
	public FilterRegistrationBean rsaFilterRegister() {
		FilterRegistrationBean bean = new FilterRegistrationBean(new RsaFilter());
		bean.addUrlPatterns(ykSecurityProperties.getLoginProcessUrl(), "/oauth/token", "/oauth/authorize");
		return bean;
	}

	@Bean
	@ConditionalOnProperty("yk.security.imgCodeEnable")
	@Order(2)
	public FilterRegistrationBean validateCodeRegister() {
		FilterRegistrationBean bean = new FilterRegistrationBean(new ValidateCodeFilter(authenticationFailureHandler, redisService));
		bean.addUrlPatterns(ykSecurityProperties.getLoginProcessUrl(), "/oauth/token");
		return bean;
	}

}
